package com.xiaoqi.api.controller.admin;


import com.xiaoqi.api.dto.ProjectDTO;
import com.xiaoqi.api.pojo.Project;
import com.xiaoqi.api.query.ProjectQuery;
import com.xiaoqi.api.service.ProjectService;
import com.xiaoqi.api.utlis.PageResult;
import com.xiaoqi.api.utlis.Result;
import com.xiaoqi.api.vo.ProjectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("admin/project")
@Api(tags = "项目管理接口")
public class ProjectController {

    @Resource
    ProjectService projectService;

    @ApiOperation("查询项目接口")
    @GetMapping
    public Result<List<ProjectVO>> find(ProjectQuery projectQuery){
        log.info("查询项目");
        PageResult<ProjectVO> page = projectService.find(projectQuery);
        return Result.ok("成功",page.getList(),page.getTotal());
    }

    @ApiOperation("查询项目接口")
    @GetMapping("/{id}")
    public Result findById(@PathVariable long id){
        log.info("查询项目");
        ProjectVO projectVO = projectService.findById(id);
        return Result.ok("成功",projectVO);
    }


    @ApiOperation("添加项目接口")
    @PostMapping
    public Result add(ProjectDTO projectDTO){
        log.info("添加信息参数为："+projectDTO.toString());
        projectService.add(projectDTO);
        return Result.ok("添加成功");
    }

    @ApiOperation("编辑项目")
    @PutMapping("/{id}")
    public Result update(@PathVariable long id, ProjectDTO projectDTO){
        log.info("编辑当前菜品id为："+id+",参数为："+projectDTO.toString());
        projectService.update(id,projectDTO);
        return Result.ok("修改成功！");
    }


}
